package com.cheng.im.service.group.controller;

import com.cheng.im.service.common.model.SyncReq;
import com.cheng.im.service.common.model.SyncResp;
import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.group.domain.ImGroup;
import com.cheng.im.service.group.model.req.*;
import com.cheng.im.service.group.model.resp.GetGroupResp;
import com.cheng.im.service.group.service.ImGroupMemberService;
import com.cheng.im.service.group.service.ImGroupService;
import com.cheng.im.service.group.service.impl.GroupMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "群")
@RestController
@RequestMapping("v1/group")
public class ImGroupController {

    @Resource
    ImGroupService imGroupService;
    @Resource
    GroupMessageService groupMessageService;

    @ApiOperation(value = "导入群")
    @PostMapping("/importGroup")
    public CommonResult importGroup(@RequestBody @Validated ImportGroupReq req)  {
        return imGroupService.importGroup(req);
    }

    @ApiOperation(value = "创建群")
    @PostMapping("/createGroup")
    public CommonResult createGroup(@RequestBody @Validated CreateGroupReq req)  {
        return imGroupService.createGroup(req);
    }

    @ApiOperation(value = "群详情")
    @PostMapping("/getGroupInfo")
    public CommonResult<GetGroupResp> getGroupInfo(@RequestBody @Validated GetGroupReq req)  {
        return imGroupService.getGroup(req);
    }

    @ApiOperation(value = "更新群")
    @PutMapping("/update")
    public CommonResult update(@RequestBody @Validated UpdateGroupReq req)  {
        return imGroupService.updateBaseGroupInfo(req);
    }

    @ApiOperation(value = "获取加入的群")
    @PostMapping("/getJoinedGroup")
    public CommonResult getJoinedGroup(@RequestBody @Validated GetJoinedGroupReq req)  {
        return imGroupService.getJoinedGroup(req);
    }

    @ApiOperation(value = "解散群")
    @DeleteMapping("/destroyGroup")
    public CommonResult destroyGroup(@RequestBody @Validated DestroyGroupReq req)  {
        return imGroupService.destroyGroup(req);
    }

    @ApiOperation(value = "转让群")
    @PutMapping("/transferGroup")
    public CommonResult transferGroup(@RequestBody @Validated TransferGroupReq req)  {
        return imGroupService.transferGroup(req);
    }

    @ApiOperation(value = "全群禁言状态开关")
    @PutMapping("/forbidSendMessage")
    public CommonResult forbidSendMessage(@RequestBody @Validated MuteGroupReq req)  {
        return imGroupService.muteGroup(req);
    }

    /**
     * todo: 还没完成
     * @param req
     * @return
     */
    @ApiOperation(value = "发送信息")
    @PostMapping("/sendMessage")
    public CommonResult sendMessage(@RequestBody @Validated SendGroupMessageReq req)  {
        return CommonResult.success();
    }

    @ApiOperation(value = "同步拉取群详情")
    @PostMapping("/syncJoinedGroup")
    public CommonResult<SyncResp<ImGroup>> syncJoinedGroup(@RequestBody @Validated SyncReq req)  {
        return imGroupService.syncJoinedGroupList(req);
    }
}
